package com.wuyan.locationdog.view

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.ImageView
import android.widget.TextView
import com.wuyan.locationdog.R
import leifu.shapelibrary.ShapeView
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig


class PayPopup(context: Context?, var price: String, var sureCallback: ((String) -> Unit)? = null) : BasePopupWindow(context) {


    var payType = "2"

    init {
        contentView = createPopupById(R.layout.pop_pay)
        popupGravity = Gravity.BOTTOM
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        findViewById<TextView>(R.id.price).text = price

        val ivCheckWechat = findViewById<ImageView>(R.id.ivCheckWechat)
        val ivCheckAlipay = findViewById<ImageView>(R.id.ivCheckAlipay)

        findViewById<View>(R.id.btnWechat).setOnClickListener {
            ivCheckWechat.setImageResource(R.mipmap.alarm_checked)
            ivCheckAlipay.setImageResource(R.mipmap.alarm_unchecked)

            payType = "2"
        }
        findViewById<View>(R.id.btnAlipay).setOnClickListener {
            ivCheckWechat.setImageResource(R.mipmap.alarm_unchecked)
            ivCheckAlipay.setImageResource(R.mipmap.alarm_checked)

            payType = "1"
        }
        findViewById<ShapeView>(R.id.btnSure).setOnClickListener {
            //支付方式 1 支付宝 2微信
            sureCallback?.invoke(payType)
            dismiss()
        }
        findViewById<View>(R.id.btnClose).setOnClickListener {
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation? {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }

}
